package leetcode.weekly.week325;

//Solution1Test
public class Solution1 {

	public int closetTarget(String[] words, String target, int startIndex) {
		int len = words.length;
		int t = 0;
		for (int i = startIndex; t < len; i++, i %= len, t++) {
			String word = words[i];
			if (word.equals(target)) {
				break;
			}
		}
		int t1 = 0;
		for (int i = startIndex; t1 < len; i--, i = (i + len) % len, t1++) {
			String word = words[i];
			if (word.equals(target)) {
				break;
			}
		}
		int ans = Math.min(t, t1);
		return ans == len ? -1 : ans;
	}

}
